package com.siloam.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.siloam.module.Prayer;
import com.siloam.module.User;
import com.siloam.service.PrayerService;
import com.siloam.vo.PageParam;
import com.siloam.vo.PageVO;
import com.siloam.vo.PrayerVO;

@Controller
@RequestMapping("/web/prayer/prayer.do")
public class PrayerController extends BaseController{

	@Resource
	private PrayerService prayerService;

	public PrayerService getPrayerService() {
		return prayerService;
	}

	public void setPrayerService(PrayerService prayerService) {
		this.prayerService = prayerService;
	}

	@RequestMapping(params="method=add")
	@ResponseBody
	public String add(Prayer prayer){
		prayer.setDate(new Date());
		//TODO 从session中取当前用户
		User u = new User();
		u.setId(6);
		prayer.setUser(u);
		prayer.setStatus(Prayer.STATUS_ING);
		
		prayerService.add(prayer);
		return SUCCESS;
	}
	
	@RequestMapping(params="method=findUserPrayers")
	@ResponseBody
	public PageVO<PrayerVO> findUserPrayers(PageParam param){
		int userId = 6;//TODO 从session取当前用户
		return prayerService.findUserPrayer(userId, param.getRowBeginIndex(), param.getRowCount());
	}
	
	@RequestMapping(params="method=deletePrayer")
	@ResponseBody
	public String deletePrayer(int id){
		prayerService.delete(id);
		return SUCCESS;
	}

	@RequestMapping(params="method=setPrayerStatus")
	@ResponseBody
	public String setPrayerStatus(int id, int status){
		prayerService.setStatus(id, status);
		return SUCCESS;
	}
	
}

